﻿using System;
using System.Windows.Forms;

namespace lab04
{
    public partial class Form1 : Form
    {
        private BwWithShadows _bwWithShadows;
        private BwWithoutShadows _bwWithoutShadows;
        private ColorWithShadows _colorWithShadows;
        private ColorWithoutShadows _colorWithoutShadows;
        private bool _isDraw;
        private MatrixVisualizator _visualizator;
        private IMatrixDrawer _matrixDrawer;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1Load(object sender, EventArgs e)
        {
            _isDraw = false;
            _colorWithoutShadows = new ColorWithoutShadows {Panel = panel1};
            _colorWithShadows = new ColorWithShadows {Panel = panel1};
            _bwWithoutShadows = new BwWithoutShadows {Panel = panel1};
            _bwWithShadows = new BwWithShadows {Panel = panel1};
            _matrixDrawer = _colorWithoutShadows;
        }

        private void DrawMe()
        {
            _visualizator.Drawer = _matrixDrawer;
            if (!_isDraw) return;
            _visualizator.Visualize();
        }



        private void Button1Click(object sender, EventArgs e)
        {
            HorizontalMatrixGroup h_group1 = new HorizontalMatrixGroup();
            {
                IMatrix tmp = new DenseMatrix(1, 1);
                MatrixRoutines.Fill(tmp, 1, 10);
                h_group1.Add(tmp);
            }

            {
                IMatrix tmp = new SparseMatrix(3, 2);
                MatrixRoutines.Fill(tmp, 5, 10);
                h_group1.Add(tmp);
            }

            {
                IMatrix tmp = new DenseMatrix(6, 2);
                MatrixRoutines.Fill(tmp, 5, 10);
                h_group1.Add(tmp);
            }

            {
                IMatrix tmp = new DenseMatrix(1, 1);
                MatrixRoutines.Fill(tmp, 1, 10);
                h_group1.Add(tmp);
            }


            HorizontalMatrixGroup h_group2 = new HorizontalMatrixGroup();
            {
                IMatrix tmp = new SparseMatrix(3, 2);
                MatrixRoutines.Fill(tmp, 5, 10);
                h_group2.Add(tmp);
            }

            {
                IMatrix tmp = new DenseMatrix(1, 3);
                MatrixRoutines.Fill(tmp, 3, 10);
                h_group2.Add(tmp);
            }

            VerticalMatrixGroup vGroup = new VerticalMatrixGroup();

            vGroup.Add(h_group1);
            vGroup.Add(h_group2);
            {
                IMatrix tmp = new DenseMatrix(2, 8);
                MatrixRoutines.Fill(tmp, 16, 10);
                vGroup.Add(tmp);
            }



            _visualizator = new MatrixVisualizator(vGroup, _matrixDrawer);

            _isDraw = true;
            DrawMe();
        }

        private void RadioButton1CheckedChanged(object sender, EventArgs e)
        {
            _matrixDrawer = _colorWithoutShadows;
            DrawMe();
        }

        private void RadioButton2CheckedChanged(object sender, EventArgs e)
        {
            _matrixDrawer = _colorWithShadows;
            DrawMe();
        }

        private void RadioButton3CheckedChanged(object sender, EventArgs e)
        {
            _matrixDrawer = _bwWithoutShadows;
            DrawMe();
        }

        private void RadioButton4CheckedChanged(object sender, EventArgs e)
        {
            _matrixDrawer = _bwWithShadows;
            DrawMe();
        }
    }
}